﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Idlesoft.Utils
{
	public static class PrintExtensions
	{


		#region print
		public static Exception Print(this Exception ex)
		{
			Console.WriteLine(ex.Expand());
			return ex;
		}
		public static TItem Print<TItem>(this TItem item)
		{
			Console.WriteLine(item);
			return item;
		}
		public static TItem Print<TItem>(this TItem item, params object[] args)
		{
			Console.WriteLine(item.ToString() + args.Flatten(" ", " ", " "));
			return item;
		}
		public static IEnumerable<TItem> Print<TItem>(this IEnumerable<TItem> items)
		{
			items.ForEach(item => item.Print());
			return items;
		}
		public static TItem[] Print<TItem>(this TItem[] items)
		{
			items.ForEach(item => item.Print());
			return items;
		}
		public static List<TItem> Print<TItem>(this List<TItem> items)
		{
			items.ForEach(item => item.Print());
			return items;
		}
		public static string Print(this string format, params object[] args)
		{
			Console.WriteLine(format, args);
			return format;
		}
		public static IEnumerable<string> Print(this IEnumerable<string> formats, params object[] args)
		{
			formats.ForEach(format => format.Print(args));
			return formats;
		}
		public static string[] Print(this string[] formats, params object[] args)
		{
			formats.ForEach(format => format.Print(args));
			return formats;
		}
		public static List<string> Print(this List<string> formats, params object[] args)
		{
			formats.ForEach(format => format.Print(args));
			return formats;
		}
		#endregion print

		#region printif
		public static TItem PrintIf<TItem>(this TItem item, Func<TItem, bool> predicate)
		{
			if (predicate.Invoke(item))
				Console.WriteLine(item);
			return item;
		}
		#endregion printif

		#region print if else
		public static TItem PrintIfElse<TItem>(this TItem item, Func<TItem, bool> predicate, object oelse)
		{
			if (predicate.Invoke(item))
				Console.WriteLine(item);
			else
				Console.WriteLine(oelse);
			return item;
		}
		#endregion print if else
	}
}
